import Vue from "vue";
import Router from "vue-router";
import routes from "./module.router";

Vue.use(Router);

const router = new Router({
  mode: 'hash',
  routes,
});
/*在跳转之前执行*/
router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  // 设置滚动位置
  if (from.meta.keepAlive)
    from.meta.scrollTop = document.documentElement.scrollTop || 0;

  next();
});
/*在跳转之后判断*/
router.afterEach((to, from) => {
  // 恢复滚动位置
  if (to.meta.scrollTop) document.documentElement.scrollTop = to.meta.scrollTop;
});

export default router;
